<template>
    <CommonContainer title="车辆信息">
        <el-descriptions v-if="customerInfo">
            <!-- <el-descriptions-item label="车牌号" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.carNo|filterNull}}</el-descriptions-item> -->
            <el-descriptions-item label="车架号" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.vinNo|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="登记证日期" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.registerTime|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="发动机号码" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.engineNo|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="车辆归属" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.ascription|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="车辆大区" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.region|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="车辆运营" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.operationsName|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="上牌城市" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.propertyRightName|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="车辆性质" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.carNature==1?'营运':'非营运'|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="车辆类型" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.carType|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="车辆种类" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.vehicleCategory|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="车辆级别" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.carLevel|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="车辆品牌" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.brandName|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="车型" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.modelName|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="车系" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.seriesName|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="燃油类型" v-if="customerInfo.carBasicVo"> <dict-tag
                        :options="dict.type.fuel_type"
                        :value="customerInfo.carBasicVo.fuelType"/></el-descriptions-item>
            <el-descriptions-item label="排量" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.liter|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="环保标准" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.environmentalStandards|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="外观颜色" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.exteriorColor|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="内饰颜色" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.interiorColor|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="座位数 " v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.seatNum|filterNull}}</el-descriptions-item>

            <!-- <el-descriptions-item label="年检到期日" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.inspectionNextTime|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="年检线上线下" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.onlineOffline==1?'线上':'线下'|filterNull}}</el-descriptions-item> -->
            <el-descriptions-item label="过户日期" v-if="customerInfo.carBasicVo">{{customerInfo.carBasicVo.transferDate|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="是否安装GPS" v-if="customerInfo.gpsDetailVo">
              <span v-if="customerInfo.gpsDetailVo.isInstallation==1">否</span>
              <span v-else-if="customerInfo.gpsDetailVo.isInstallation==0">是</span>
              <span v-else>--</span>

            </el-descriptions-item>
            <el-descriptions-item label="GPS品牌" v-if="customerInfo.gpsDetailVo">{{customerInfo.gpsDetailVo.gpsBrand|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="GPS设备类型" v-if="customerInfo.gpsDetailVo && customerInfo.carInStorage.purchaseSource!=='4'">{{customerInfo.gpsDetailVo.gpsType|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="GPS设备状态" v-if="customerInfo.gpsDetailVo && customerInfo.carInStorage.purchaseSource!=='4'">{{customerInfo.gpsDetailVo.gpsState|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="GPS开始时间" v-if="customerInfo.gpsDetailVo && customerInfo.carInStorage.purchaseSource!=='4'">{{customerInfo.gpsDetailVo.installTime|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="GPS结束时间" v-if="customerInfo.gpsDetailVo && customerInfo.carInStorage.purchaseSource!=='4'">{{customerInfo.gpsDetailVo.expireTime|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="投保渠道 " v-if="customerInfo.insuranceStorageDetailVo">{{customerInfo.insuranceStorageDetailVo.insuranceChannels|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="商业险保险公司名称" v-if="customerInfo.insuranceStorageDetailVo">{{customerInfo.insuranceStorageDetailVo.syxCompany|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="商业险保险金额" v-if="customerInfo.insuranceStorageDetailVo">{{customerInfo.insuranceStorageDetailVo.syxAmount|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="商业险时效" v-if="customerInfo.insuranceStorageDetailVo">{{customerInfo.insuranceStorageDetailVo.syxValidity|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="交强险保险公司名称" v-if="customerInfo.insuranceStorageDetailVo">{{customerInfo.insuranceStorageDetailVo.jqxCompany|filterNull}}</el-descriptions-item>  
            <el-descriptions-item label="交强险保险金额" v-if="customerInfo.insuranceStorageDetailVo">{{customerInfo.insuranceStorageDetailVo.jqxAmount|filterNull}}</el-descriptions-item> 
            <el-descriptions-item label="交强险时效" :span="2" v-if="customerInfo.insuranceStorageDetailVo">{{customerInfo.insuranceStorageDetailVo.jqxValidity|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="购车发票" v-if="customerInfo.carBasicVo && customerInfo.carInStorage.purchaseSource!=='4'">
                <image-common v-model="customerInfo.carBasicVo.buyCarInvoiceOss" disabled :up-type="2"></image-common>
            </el-descriptions-item>
            <el-descriptions-item label="购置税发票" v-if="customerInfo.carBasicVo && customerInfo.carInStorage.purchaseSource!=='4'">
                <image-common v-model="customerInfo.carBasicVo.paidTaxesInvoiceOss" disabled :up-type="2"></image-common>
            </el-descriptions-item>

            <el-descriptions-item label="交强险保单" v-if="customerInfo.insuranceStorageDetailVo">
                <image-common v-model="customerInfo.insuranceStorageDetailVo.jqxPolicyCode" disabled :up-type="2"></image-common>
            </el-descriptions-item>
            <el-descriptions-item label="商业险保单" v-if="customerInfo.insuranceStorageDetailVo">
                <image-common v-model="customerInfo.insuranceStorageDetailVo.syxPolicyCode" disabled :up-type="2"></image-common>
            </el-descriptions-item>
            <el-descriptions-item label="GPS免安装证明" v-if="customerInfo.gpsDetailVo && customerInfo.carInStorage.purchaseSource!=='4'">
                <image-common v-model="customerInfo.gpsDetailVo.gpsProve" disabled :up-type="2"></image-common>
            </el-descriptions-item>

        </el-descriptions>
    </CommonContainer>
</template>
<script>
import {
  getPurchaseQualifiedCard, carGpsInstall, getQuotaProductByOrderCar, carGpsMonitoring, carPrchaseTax, carInspection, carInsurance, carInspectionNextTime
} from "@/api/carInventory/inInventory";
import moment from "moment";
export default {
    components: {},
    dicts: ['fuel_type'],
    props: {
        value: {
        type: Object,
        },
    },
    data() {
        return {
            ossId: '1759761984477720577',
        }
    },
    computed:{
        customerInfo: {
            get() {
                return this.value;
                return this.useVModel.call(this);
            },
            set(val) {
                this.$emit("input", val);
            }, 
        },
    },
    methods: {
      getQualifiedCard(purchaseNo,vinNo){
        if (this.Empty(purchaseNo) || this.Empty(vinNo)) return;
        getPurchaseQualifiedCard(purchaseNo, vinNo).then(res => {
          var pd = res.data;
          if (!pd) {
            pd = {};
          }
          // this.customerInfo.carBasicVo.carLevel = pd.carLevel;
          // this.customerInfo.carBasicVo.exteriorColor = pd.exteriorColor;
          // this.customerInfo.carBasicVo.interiorColor = pd.interiorColor;
          // this.customerInfo.carBasicVo.carType = pd.carType;
          // this.customerInfo.carBasicVo.vehicleCategory = pd.vehicleCategory;
        }).finally(() => {
          this.loading = false
        })
      },
      getCarGpsInfo(carId){
        if (this.Empty(carId)) return;
        carGpsInstall(carId).then(res => {
          var d = res.data;
          if (!d) {
            d = {};
          }
          this.customerInfo.gpsDetailVo.gpsType = {'1':'有线','2':'无线','3':'有线+无线'}[new String(d.equipmentType).trim()];
          var year = d.gpsServicePeriod?.match(/\d*/)[0]
          this.customerInfo.gpsDetailVo.installTime = d.installTime;
          this.customerInfo.gpsDetailVo.expireTime = d.installTime?moment(d.installTime).add(year^0, 'years').format("YYYY-MM-DD HH:mm:ss"):null;
        }).finally(() => {
          this.loading = false
        })
      },
      getQuota(orderCode, carModelName){
        if (this.Empty(orderCode)) return;
        if (this.Empty(carModelName)) return;
        getQuotaProductByOrderCar(orderCode, carModelName).then(res => {
          var pd = res.data;
          if (!pd) {
            pd = {};
          }
          if (!pd['plan']) {
            pd['plan'] = {};
          }
          this.customerInfo.insuranceStorageDetailVo.syxAmount = pd.insuranceCommercialCurrentAmount;
          this.customerInfo.insuranceStorageDetailVo.jqxAmount = pd.insuranceCompulsoryCurrentAmount;
        }).finally(() => {
          this.loading = false
        })
      },
      getCarGpsMonitoring(carId){
        if (this.Empty(carId)) return;
        carGpsMonitoring(carId).then(res => {
          var d = res.data;
          if (!d) {
            d = {};
          }
          this.customerInfo.gpsDetailVo.gpsState = d?.gpsState;
        }).finally(() => {
          this.loading = false
        })
      },
      getCarPrchaseTax(carId){
        if (this.Empty(carId)) return;
        carPrchaseTax(carId).then(res => {
          var d = res.data;
          if (!d) {
            d = {};
          }
          this.customerInfo.carBasicVo.paidTaxesInvoiceOss = d.invoiceUrl;
        }).finally(() => {
          this.loading = false
        })
      },
      getCarInspection(carId){
        if (this.Empty(carId)) return;
        carInspection(carId).then(res => {
          var d = res.data;
          if (!d) {
            d = {};
          }
          this.customerInfo.carBasicVo.inspectionNextTime = d.inspectionNextTime;
        }).finally(() => {
          this.loading = false
        })
      },
      getCarInspectionNextTime(carId){
        if (this.Empty(carId)) return;
        carInspectionNextTime(carId).then(res => {
          var d = res.data;
          this.customerInfo.carBasicVo.inspectionNextTime = d;
        }).finally(() => {
          this.loading = false
        })
      },
      getCarInsurance(carId){
        if (this.Empty(carId)) return;
        //1交强险
        carInsurance(carId, 1).then(res => {
          var d = res.data;
          if (!d) {
            return
          }
          this.customerInfo.insuranceStorageDetailVo.jqxCompany = d.insuranceCompany;
          this.customerInfo.insuranceStorageDetailVo.jqxValidity = d?d.actualBeginTime + '-' + d.actualEndTime:'--'
          if (d.insuranceChannels) {
            this.customerInfo.insuranceStorageDetailVo.insuranceChannels = {'1':'我司购买','2':'店端投保','3':'客户自购'}[new String(d.insuranceChannels).trim()];
          }
          this.customerInfo.insuranceStorageDetailVo.jqxAmount = d.insuranceAmount;
        }).finally(() => {
          this.loading = false
        })
        //2商业险
        carInsurance(carId, 2).then(res => {
          var d = res.data;
          if (!d) {
            return
          }
          this.customerInfo.insuranceStorageDetailVo.syxCompany = d.insuranceCompany;
          this.customerInfo.insuranceStorageDetailVo.syxValidity = d?d.actualBeginTime + '-' + d.actualEndTime:'--'
          if (d.insuranceChannels) {
            this.customerInfo.insuranceStorageDetailVo.insuranceChannels = {'1':'我司购买','2':'店端投保','3':'客户自购'}[new String(d.insuranceChannels).trim()];
          }
          this.customerInfo.insuranceStorageDetailVo.syxAmount = d.insuranceAmount;
        }).finally(() => {
          this.loading = false
        })
      },
      detailInfo(){
        console.log(this.customerInfo,'this.customerInfothis.customerInfo')
        var _this = this;
        if (this.customerInfo != null && this.customerInfo.carInStorage != null) {
          // 自主采购的接口
            // this.getQualifiedCard(this.customerInfo.carInStorage.purchaseNo, this.customerInfo.carBasicVo.vinNo);
            // 需要列表id
            const param = {
              inboundId:this.customerInfo.inboundId?this.customerInfo.inboundId:-1,
              carId:this.customerInfo.carInStorage.carId?this.customerInfo.carInStorage.carId:-1,
            }
            this.getCarGpsInfo(param);
            this.getCarGpsMonitoring(this.customerInfo.carInStorage.carId);
            this.getCarPrchaseTax(this.customerInfo.carInStorage.carId);
            // 需要列表id
            this.getCarInsurance(this.customerInfo.inboundId);
            this.getCarInspectionNextTime(this.customerInfo.carInStorage.carId);
        } else {
          setTimeout(function () {
            _this.detailInfo();
          }, 100)
        }
      },
    },
  created() {

    this.detailInfo()
  },
  mounted() {

    },
}
</script>

<style lang="scss" scoped>
</style>